//
//  MJPhoto.m
//
//  Created by mj on 13-3-4.
//  Copyright (c) 2013年 itcast. All rights reserved.

#import <QuartzCore/QuartzCore.h>
#import "MJPhoto.h"

@implementation MJPhoto

#pragma mark 截图
//- (UIImage *)capture:(UIView *)view
//{
//    UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0.0);
//    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
//    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
//    UIGraphicsEndImageContext();
//    return img;
//}
#pragma mark -- 圆形图片
- (UIImage *)capture:(UIImage *)image
{
    int w = image.size.width;
    int h = image.size.height;
    UIImage *img = image;
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);
    CGRect rect = CGRectMake(0, 0, w, h);
    CGContextBeginPath(context);
    CGContextAddEllipseInRect(context, rect);
    CGContextClosePath(context);
    CGContextClip(context);
    CGContextDrawImage(context, rect, img.CGImage);
    CGImageRef imageMasked = CGBitmapContextCreateImage(context);
    CGContextRelease(context);
    CGColorSpaceRelease(colorSpace);
    return [UIImage imageWithCGImage:imageMasked];
}
- (void)setSrcImageView:(UIImageView *)srcImageView
{
    _srcImageView = srcImageView;
    _placeholder = srcImageView.image;
    _capture = [self capture:srcImageView.image];

    if (srcImageView.clipsToBounds) {
           }else{
        _capture=srcImageView.image;
    }
}
-(void)setXingcheng:(UIImageView *)xingcheng{
    _xingcheng = xingcheng;
    _placeholder = xingcheng.image;
//    if (_xingcheng.clipsToBounds) {
//        _capture = _xingcheng.image;
//    }

    
}


-(void)setSrcBtn:(UIButton *)srcBtn{
    
    _srcBtn = srcBtn;
    _placeholder = srcBtn.imageView.image;
    _capture=_srcBtn.imageView.image;

    if (_srcBtn.clipsToBounds) {
        _capture = [self capture:srcBtn.imageView.image];
    }else{
            }

    if (srcBtn.width == srcBtn.height) {
        _capture = _placeholder;
    }
    
}

@end